package com.example.panda.mine;

import android.content.Context;
import android.content.Intent;
import android.icu.text.Transliterator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.panda.R;
import com.example.panda.service.ChatActivity;

import java.util.List;

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> implements View.OnClickListener {

    private List<list> mData;
    private Context mContext;
    private  OnItemClickListener monItemClickListener = null;


    public RecyclerAdapter(Context context, List<list> data,OnItemClickListener monItemClickListener){
        mContext = context;
        mData = data;
        this.monItemClickListener = monItemClickListener;
    }

    @NonNull
    @Override
    public RecyclerAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        LayoutInflater inflater = LayoutInflater.from(mContext);
        view = inflater.inflate(R.layout.recycler_item,parent,false);
        view.setOnClickListener((View.OnClickListener) this);
        final MyViewHolder viewHolder = new MyViewHolder(view);

//        viewHolder.view_contain.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(mContext, ChatActivity.class);
//                startActivity(intent);
//            }
//        });
        return viewHolder;
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerAdapter.MyViewHolder holder, int position) {

        holder.tv_name.setText(mData.get(position).getTv());
        holder.iv_1.setImageResource(mData.get(position).getIv1());
        holder.iv_2.setImageResource(mData.get(position).getIv2());
        holder.kk.setVisibility(mData.get(position).getKk());

        holder.view_contain.setTag(position);



    }

    @Override
    public void onClick(View v) {
        monItemClickListener.onItemClick(v,((int) v.getTag()));
    }


    public static  class MyViewHolder extends  RecyclerView.ViewHolder{
        TextView tv_name;
        LinearLayout view_contain,li;
        ImageView iv_1,iv_2;
        View kk;
//        OnItemClickListener onItemClickListener;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);

//            onItemClickListener = onItemClickListener1;
//            itemView.setOnClickListener((View.OnClickListener) this);

            view_contain = itemView.findViewById(R.id.recycler_item);
            li = itemView.findViewById(R.id.item_re);
            kk = itemView.findViewById(R.id.kk);
            tv_name = itemView.findViewById(R.id.tv2);
            iv_1 = itemView.findViewById(R.id.iv1);
            iv_2 = itemView.findViewById(R.id.iv2);
        }



    }



}
